package com.shenmazong.servernewsapi.controller;

import com.shenmazong.servernewsapi.service.NewsMongoService;
import com.shenmazong.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "接口-用户信息服务")
public class NewsMongoController {

    @Autowired
    NewsMongoService newsMongoService;

    @PostMapping(value = "/addUserNewsByMongo")
    @ApiOperation(value = "添加服务信息", notes = "添加服务信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Long", example = "0"),
            @ApiImplicitParam(name = "longitude", value = "经度", required = true, dataType = "String"),
            @ApiImplicitParam(name = "latitude", value = "纬度", required = true, dataType = "String"),
            @ApiImplicitParam(name = "serviceType", value = "服务类型", required = true, dataType = "Long", example = "0"),
            @ApiImplicitParam(name = "title", value = "标题", required = true, dataType = "String"),
            @ApiImplicitParam(name = "content", value = "服务内容", required = true, dataType = "String"),
    })
    public ResponseResult addUserNews(@RequestParam("userId") Integer userId,
                                      @RequestParam("longitude") Double longitude,
                                      @RequestParam("latitude") Double latitude,
                                      @RequestParam("serviceType") Integer serviceType,
                                      @RequestParam("title") String title,
                                      @RequestParam("content") String content) {
        return newsMongoService.addUserNews(userId, longitude, latitude, serviceType, title, content);
    }

    @PostMapping(value = "/delUserNewsByMongo")
    @ApiOperation(value = "删除服务信息", notes = "删除服务信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Long", example = "0"),
            @ApiImplicitParam(name = "newsId", value = "服务信息ID", required = true, dataType = "Long", example = "0")
    })
    public ResponseResult delUserNewsById(@RequestParam("userId") Integer userId,
                                          @RequestParam("newsId") Long newsId) {
        return newsMongoService.delUserNewsById(userId, newsId);
    }

    @PostMapping(value = "/setUserNewsByMongo")
    @ApiOperation(value = "修改服务信息", notes = "修改服务信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Long", example = "0"),
            @ApiImplicitParam(name = "newsId", value = "服务信息ID", required = true, dataType = "Long", example = "0"),
            @ApiImplicitParam(name = "longitude", value = "经度", required = true, dataType = "String"),
            @ApiImplicitParam(name = "latitude", value = "纬度", required = true, dataType = "String"),
            @ApiImplicitParam(name = "serviceType", value = "服务类型", required = true, dataType = "Long", example = "0"),
            @ApiImplicitParam(name = "title", value = "标题", required = true, dataType = "String"),
            @ApiImplicitParam(name = "content", value = "服务内容", required = true, dataType = "String")
    })
    public ResponseResult setUserNews(@RequestParam("userId") Integer userId,
                                      @RequestParam("newsId") Long newsId,
                                      @RequestParam("longitude") Double longitude,
                                      @RequestParam("latitude") Double latitude,
                                      @RequestParam("serviceType") Integer serviceType,
                                      @RequestParam("title") String title,
                                      @RequestParam("content") String content) {
        return newsMongoService.setUserNews(userId, newsId, longitude, latitude, serviceType, title, content);
    }

    @PostMapping(value = "/getNewsByUserIdByMongo")
    @ApiOperation(value = "获取服务信息", notes = "获取服务信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Long", example = "0"),
            @ApiImplicitParam(name = "pageNo", value = "当前页码", required = true, dataType = "Long", example = "0"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = true, dataType = "Long", example = "0")
    })
    public ResponseResult getNewsByUserId(@RequestParam("userId") Integer userId,
                                          @RequestParam("pageNo") Integer pageNo,
                                          @RequestParam("pageSize") Integer pageSize) {
        return newsMongoService.getNewsByUserId(userId, pageNo, pageSize);
    }

    @PostMapping(value = "/getNewsByTypeIdByMongo")
    public ResponseResult getNewsByTypeId(@RequestParam("userId") Integer userId,
                                          @RequestParam("typeId") Integer typeId,
                                          @RequestParam("pageNo") Integer pageNo,
                                          @RequestParam("pageSize") Integer pageSize) {
        return newsMongoService.getNewsByTypeId(userId, typeId, pageNo, pageSize);
    }
}
